home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / House Picture ƒ / house picture.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  5.9 KB  |  195 lines  |  [TEXT/KAHL]

  1. /*
  2.     House picture
  3.  
  4.     This application will create a picture of a house.  Each object in the picture will represent one piece of the house.
  5.     The border of the house and the window frames are created with polygons.  The door is created with a rectangle. Each object
  6.     is added to the picture with a call to AddToPicture.  The color of various objects by adding an ink to the object.
  7.     
  8.     NOTES:
  9.     • This file requires the following files to run correctly:
  10.         "graphics shell.c", "color library.c", "graphics debug library.c", "picture library.c", 
  11.         "shape library.c", "transform library.c".
  12.         
  13.     • This file prints the "best" in landscape mode.
  14.  
  15.     ©1990 - 1994  Apple Computer, Inc.
  16.     All rights reserved.
  17. */
  18.  
  19. #include <Events.h>
  20. #include <FixMath.h>
  21. #include <Windows.h>
  22.  
  23. #include "graphics libraries.h"
  24. #include "graphics toolbox.h"
  25. #include "graphics shell.h"
  26.  
  27.  
  28. //
  29. //  Set up the title and size of the window 
  30. //
  31. Str255         gWindowTitle = "\pHouse Picture";
  32. Rect         gWindowQDRect  = {40, 10, 185, 275};
  33.  
  34.  
  35. //
  36. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
  37. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  38. //    With  gGraphicsHeapSize set to 25k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  39. //
  40. long        gGraphicsHeapSize = 25;
  41.  
  42. gxShape     gOurHouse;
  43.  
  44.  
  45.  
  46. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  47.  
  48. void DoInitialization(aWindow)
  49. WindowPtr aWindow;
  50. {
  51.     long         windowGeometry[] = {3, // number of contours 
  52.                                        4, // points in frame
  53.                                        0, 0,  ff(30), 0,  ff(30), ff(30),  0, ff(30), // window frame
  54.                                     2, // points in vertical crossbar 
  55.                                     ff(15), 0, ff(15), ff(30),
  56.                                     2, // points in horizontal crossbar
  57.                                     0, ff(15), ff(30), ff(15)};
  58.  
  59.     long         houseGeometry[] = {    7, // number of points in the house border
  60.                                        0, ff(10),  
  61.                                        0, ff(30),  
  62.                                        ff(100), ff(30),  
  63.                                        ff(100), ff(10),  
  64.                                        0, ff(10),
  65.                                        ff(50), 0,  
  66.                                        ff(100), ff(10)};
  67.     
  68.     gxRectangle     doorGeometry = {ff(45), ff(15), ff(55), ff(30)};
  69.     gxShape         windowShape, houseBorderShape, doorShape;
  70.     gxTransform     newWindowTransform; 
  71.  
  72.     gOurHouse = GXNewShape(gxPictureType);
  73.     
  74.     windowShape = GXNewPolygons((gxPolygons *) windowGeometry);
  75.     houseBorderShape = NewPolygon((gxPolygon *) houseGeometry);
  76.     doorShape = GXNewRectangle(&doorGeometry);
  77.  
  78.     //
  79.     //    Set up the fillType and style for the house border
  80.     // 
  81.     {
  82.         gxStyle thickPen = GXNewStyle();
  83.                 
  84.         GXSetShapeFill(houseBorderShape, gxHollowFill);
  85.         GXSetStylePen(thickPen, ff(1));
  86.     
  87.         AddToPicture(gOurHouse, houseBorderShape, thickPen, nil, nil);
  88.         GXDisposeShape(houseBorderShape);
  89.         GXDisposeStyle(thickPen);
  90.     }
  91.     
  92.     GXSetShapeFill(doorShape, gxHollowFill);
  93.     AddToShape(gOurHouse, doorShape);
  94.     GXDisposeShape(doorShape);
  95.  
  96.     //
  97.     //    We will add the window to our house four times. We move the window within the picture by creating
  98.     //    a new transform each time through the loop. We will also add an ink to each window.
  99.     //
  100.     {    short counter;
  101.     
  102.         GXSetShapeFill(windowShape, gxHollowFill);
  103.  
  104.         for (counter = 2; counter <= 5; counter++)
  105.         {    gxTransform newTransform = GXNewTransform();
  106.         
  107.             GXScaleTransform(newTransform, fixed1/3, fixed1/3, 0, 0);
  108.             if (counter <= 3)
  109.                 GXMoveTransform(newTransform, counter * ff(15) - ff(20), ff(15));
  110.             else
  111.                 GXMoveTransform(newTransform, counter * ff(15) + ff(5), ff(15));
  112.             
  113.             if (counter == 2) 
  114.             {    gxInk redInk = GXNewInk();
  115.                 
  116.                 SetInkCommonColor(redInk, red);  
  117.         
  118.                 AddToPicture(gOurHouse, windowShape, nil, redInk, newTransform);
  119.         
  120.                 GXDisposeInk(redInk);
  121.             } else if (counter == 3)
  122.             {    gxInk grayInk = GXNewInk();
  123.             
  124.                 SetInkCommonColor(grayInk, gxGray);  
  125.                 AddToPicture(gOurHouse, windowShape, nil, grayInk, newTransform);
  126.                 GXDisposeInk(grayInk);
  127.  
  128.             } else 
  129.                 {     gxInk turquoiseInk = GXNewInk();
  130.                         SetInkCommonColor(turquoiseInk, turquoise);  
  131.  
  132.                     AddToPicture(gOurHouse, windowShape, nil, turquoiseInk, newTransform);
  133.                     GXDisposeInk(turquoiseInk);
  134.                 }
  135.                 GXDisposeTransform(newTransform);
  136.         }
  137.         GXDisposeShape(windowShape); 
  138.     }
  139.  
  140.     GXMoveShape(gOurHouse, ff(25), ff(25));
  141.      GXScaleShape(gOurHouse, fl(1.75), fl(1.75),  0, 0); 
  142. }
  143.  
  144.  
  145. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  146.  
  147. void DoDraw(aWindow)
  148. WindowPtr aWindow;
  149. {
  150.     //
  151.     //    I am not exactly sure why GX graphics is posting this notice here, but I did not want to see it. I
  152.     //    think it is a bug... I will look inot this problem before the next CD. Stay tuned to this space for coming details...
  153.     //
  154.     GXIgnoreGraphicsNotice(transform_viewPorts_already_set);
  155.  
  156.     GXDrawShape(gOurHouse);
  157.     
  158.     GXPopGraphicsNotice();
  159. }
  160.  
  161.  
  162. /*------ DoDispose -------------------------------------------------------------------------------------*/
  163.  
  164. void DoDispose(aWindow)
  165. WindowPtr aWindow;
  166. {
  167.     //  
  168.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  169.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  170.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  171.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  172.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  173.     //
  174.     DisposeCommonColors ();
  175.     GXDisposeShape(gOurHouse);
  176.     GXDisposeShape(gWindowBoundsShape);
  177.     DisposeWindow(aWindow);
  178. }
  179.  
  180.  
  181. /*------ DoClick ---------------------------------------------------------------------------------------*/
  182.  
  183. void DoClick( orgMouseLoc, theWindow )
  184. gxPoint        orgMouseLoc;
  185. WindowPtr     theWindow;
  186. {
  187. }
  188.  
  189.  
  190. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  191.  
  192. void DoIdle(aWindow)
  193. WindowPtr aWindow;
  194. {
  195. }